//
//  CustomFooter.swift
//  刷新尾
//
//  Created by mini on 2025/4/28.
//

import Foundation
import UIKit
import MJRefresh

class CustomFooter: MJRefreshBackFooter {
    // MARK: - lazy
    lazy var labeTitle: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = COLOR_DETAIL()
        label.textAlignment = .center
        return label
    }()
    
    // MARK: - 重写override
    override func prepare() {
        super.prepare()
        self.addSubview(self.labeTitle)
    }
    
    override func placeSubviews() {
        super.placeSubviews()
        self.labeTitle.width = SCREEN_WIDTH
        self.labeTitle.centerXCenterY = XY(self.width/2, self.height/2)
    }
    
    // MARK: - 监听scrollView的contentOffset改变
    override func scrollViewContentOffsetDidChange(_ change: [AnyHashable : Any]?) {
        super.scrollViewContentOffsetDidChange(change)
    }
    
    // MARK: - 监听scrollView的contentSize改变
    override func scrollViewContentSizeDidChange(_ change: [AnyHashable : Any]?) {
        super.scrollViewContentSizeDidChange(change)
    }

    // MARK: - 监听scrollView的拖拽状态改变
    override func scrollViewPanStateDidChange(_ change: [AnyHashable : Any]?) {
        super.scrollViewPanStateDidChange(change)
    }
    
    // MARK: - 监听控件的刷新状态
    override var state: MJRefreshState {
        didSet {
            // 检测到 state 值的改变
            switch state {
            case .idle:
                self.labeTitle.fitTitle("Pull up to load more", variable: 0)
                break;
            case .pulling:
                self.labeTitle.fitTitle("Release refresh", variable: 0)
                break;
            case .refreshing:
                self.labeTitle.fitTitle("Loading...", variable: 0)
                break;
            case .willRefresh:
                // print("将要刷新")
                break
            case .noMoreData:
                self.labeTitle.fitTitle("No more data", variable: 0)
                break;
            default:
                break
            }
        }
    }
}
